package com.jiyun.service;


import com.jiyun.mapper.FaDanMapper;
import com.jiyun.mapper.MessagePondMapper;
import com.jiyun.mapper.UserMapper;
import com.jiyun.pojo.entity.MessagePond;
import com.jiyun.pojo.entity.Order;
import com.jiyun.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouTaiService {
    @Autowired(required = false)
    private FaDanMapper faDanMapper;
    @Autowired(required = false)
    private MessagePondMapper messagePondMapper;
    @Autowired(required = false)
    private UserMapper userMapper;

    public void shenhetongguo(Integer oid) {
        Order order = faDanMapper.selectOrderByid(oid);
        if (order.getEstimate()!=null) {
            order.setStatusid(7);
            order.setAuditstatus(0);
            faDanMapper.updateByPrimaryKeySelective(order);
        }else {
            order.setStatusid(3);
            order.setAuditstatus(0);
            faDanMapper.updateByPrimaryKeySelective(order);
            Integer userid = order.getUserid();
            User user = userMapper.selectByPrimaryKey(userid);
            MessagePond messagePond = new MessagePond(order.getOid(), order.getOrdername(), order.getOrderimage(), order.getBilltime(), order.getStatusid(), user.getNickname(), order.getAmout());
            System.out.println(messagePond);
            messagePondMapper.insertSelective(messagePond);
        }
    }

    public Order shenheweitongguo(Integer oid, String refused) {
        Order order = faDanMapper.selectOrderByid(oid);
        order.setStatusid(2);
        order.setAuditstatus(1);
        order.setYuanyin(refused);
        faDanMapper.updateByPrimaryKeySelective(order);
        Order order1=faDanMapper.selectByPrimaryKey(order.getOid());
        return order1;
    }
    public List<Order> selectWherestatusid() {
        return faDanMapper.selectWherestatusid();
    }
}
